home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / xlisp / xlisp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  14.5 KB  |  439 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         xlisp.h
  5. * RCS:          $Header: xlisp.h,v 1.9 91/03/14 03:37:06 mayer Exp $
  6. * Description:  libXlisp.a external interfaces
  7. * Author:       David Michael Betz; Niels Mayer
  8. * Created:      
  9. * Modified:     Fri Oct  4 04:04:11 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41.  
  42. /* system specific definitions */
  43. /* #define UNIX */
  44.  
  45. #include <stdio.h>
  46. #include <ctype.h>
  47. #include <setjmp.h>
  48.  
  49. /* NNODES    number of nodes to allocate in each request (1000) */
  50. /* EDEPTH    evaluation stack depth (2000) */
  51. /* ADEPTH    argument stack depth (1000) */
  52. /* FORWARD    type of a forward declaration () */
  53. /* LOCAL    type of a local function (static) */
  54. /* AFMT        printf format for addresses ("%x") */
  55. /* FIXTYPE    data type for fixed point numbers (long) */
  56. /* ITYPE    fixed point input conversion routine type (long atol()) */
  57. /* ICNV        fixed point input conversion routine (atol) */
  58. /* IFMT        printf format for fixed point numbers ("%ld") */
  59. /* FLOTYPE    data type for floating point numbers (float) */
  60. /* OFFTYPE    number the size of an address (int) */
  61.  
  62. #ifdef WINTERP            /* WINTERP assumes UNIX */
  63. #define XLISP_VERSION_INT 2 /* used in ../winterp.c */
  64. #define XLISP_REVISION_INT 10 /* used in ../winterp.c */
  65. #define NNODES        2000
  66. #define AFMT        "%lx"
  67. #define OFFTYPE        long
  68. /* #define SAVERESTORE */  /* NOTE: WINTERP breaks save/restore functionality
  69.                               because I haven't implemented a way to make
  70.                   Xtoolkit/Motif objects (WIDGETOBJs, PIXMAPs, PIXELs,
  71.                   CALLBACKOBJs, TIMEOUTOBJs, EVHANDLEROBJs) persist across
  72.                   invocations. Currently all the code in xlimage.c just
  73.                   assumes that all pointers are xlisp pointers and
  74.                   doesn't try to handle pointers to objects created
  75.                   outside of xlisp. Implementing save/restore for
  76.                   WINTERP is doable, but is not high on my priority
  77.                   list right now. Note that WINTERP doesn't break
  78.                   save/restore for standard xlisp objects. However, since
  79.                   it doesn't work correctly I've disabled it for now. */
  80. #endif
  81.  
  82. /* for BSD & SYSV Unix. */
  83. #ifdef UNIX
  84. #define NNODES        2000
  85. #define AFMT        "%lx"    /* added by NPM */
  86. #define OFFTYPE        long    /* added by NPM */
  87. #define SAVERESTORE
  88. #endif
  89.  
  90. /* for the Turbo C compiler - MS-DOS, large model */
  91. #ifdef _TURBOC_
  92. #define NNODES        2000
  93. #define AFMT        "%lx"
  94. #define OFFTYPE        long
  95. #define SAVERESTORE
  96. #endif
  97.  
  98. /* for the AZTEC C compiler - MS-DOS, large model */
  99. #ifdef AZTEC_LM
  100. #define NNODES        2000
  101. #define AFMT        "%lx"
  102. #define OFFTYPE        long
  103. #define CVPTR(x)    ptrtoabs(x)
  104. #define NIL        (void *)0
  105. extern long ptrtoabs();
  106. #define SAVERESTORE
  107. #endif
  108.  
  109. /* for the AZTEC C compiler - Macintosh */
  110. #ifdef AZTEC_MAC
  111. #define NNODES        2000
  112. #define AFMT        "%lx"
  113. #define OFFTYPE        long
  114. #define NIL        (void *)0
  115. #define SAVERESTORE
  116. #endif
  117.  
  118. /* for the AZTEC C compiler - Amiga */
  119. #ifdef AZTEC_AMIGA
  120. #define NNODES        2000
  121. #define AFMT        "%lx"
  122. #define OFFTYPE        long
  123. #define NIL        (void *)0
  124. #define SAVERESTORE
  125. #endif
  126.  
  127. /* for the Lightspeed C compiler - Macintosh */
  128. #ifdef LSC
  129. #define NNODES        2000
  130. #define AFMT        "%lx"
  131. #define OFFTYPE        long
  132. #define NIL        (void *)0
  133. #define SAVERESTORE
  134. #endif
  135.  
  136. /* for the Microsoft C compiler - MS-DOS, large model */
  137. #ifdef MSC
  138. #define NNODES        2000
  139. #define AFMT        "%lx"
  140. #define OFFTYPE        long
  141. #endif
  142.  
  143. /* for the Mark Williams C compiler - Atari ST */
  144. #ifdef MWC
  145. #define AFMT        "%lx"
  146. #define OFFTYPE        long
  147. #endif
  148.  
  149. /* for the Lattice C compiler - Atari ST */
  150. #ifdef LATTICE
  151. #define FIXTYPE        int
  152. #define ITYPE        int atoi()
  153. #define ICNV(n)        atoi(n)
  154. #define IFMT        "%d"
  155. #endif
  156.  
  157. /* for the Digital Research C compiler - Atari ST */
  158. #ifdef DR
  159. #define LOCAL
  160. #define AFMT        "%lx"
  161. #define OFFTYPE        long
  162. #undef NULL
  163. #define NULL        0L
  164. #endif
  165.  
  166. /* default important definitions */
  167. #ifndef NNODES
  168. #define NNODES        1000
  169. #endif
  170. #ifndef EDEPTH
  171. #define EDEPTH        2000
  172. #endif
  173. #ifndef ADEPTH
  174. #define ADEPTH        1000
  175. #endif
  176. #ifndef FORWARD
  177. #define FORWARD
  178. #endif
  179. #ifndef LOCAL
  180. #define LOCAL        static
  181. #endif
  182. #ifndef AFMT
  183. #define AFMT        "%x"
  184. #endif
  185. #ifndef FIXTYPE
  186. #define FIXTYPE        long
  187. #endif
  188. #ifndef ITYPE
  189. #define ITYPE        long atol()
  190. #endif
  191. #ifndef ICNV
  192. #define ICNV(n)        atol(n)
  193. #endif
  194. #ifndef IFMT
  195. #define IFMT        "%ld"
  196. #endif
  197. #ifndef FLOTYPE
  198. #define FLOTYPE        double
  199. #endif
  200. #ifndef OFFTYPE
  201. #define OFFTYPE        int
  202. #endif
  203. #ifndef CVPTR
  204. #define CVPTR(x)    (x)
  205. #endif
  206. #ifndef UCHAR
  207. #define UCHAR        unsigned char
  208. #endif
  209.  
  210. /* useful definitions */
  211. #define TRUE    1
  212. #define FALSE    0
  213. #ifndef NIL
  214. #define NIL    (LVAL )0
  215. #endif
  216.  
  217. /* include the dynamic memory definitions */
  218. #include "xldmem.h"
  219.  
  220. /* program limits */
  221. #define STRMAX        100        /* maximum length of a string constant */
  222. #ifdef WINTERP
  223. #define HSIZE        1019        /* symbol hash table size */
  224. #else
  225. #define HSIZE        199        /* symbol hash table size */
  226. #endif
  227. #define SAMPLE        100        /* control character sample rate */
  228.  
  229. /* function table offsets for the initialization functions */
  230. #define FT_RMHASH    0
  231. #define FT_RMQUOTE    1
  232. #define FT_RMDQUOTE    2
  233. #define FT_RMBQUOTE    3
  234. #define FT_RMCOMMA    4
  235. #define FT_RMLPAR    5
  236. #define FT_RMRPAR    6
  237. #define FT_RMSEMI    7
  238. #define FT_CLNEW    10
  239. #define FT_CLISNEW    11
  240. #define FT_CLANSWER    12
  241. #define FT_OBISNEW    13
  242. #define FT_OBCLASS    14
  243. #define FT_OBSHOW    15
  244.  
  245. /* macro to push a value onto the argument stack */
  246. #define pusharg(x)    {if (xlsp >= xlargstktop) xlargstkoverflow();\
  247.              *xlsp++ = (x);}
  248.  
  249. /* macros to protect pointers */
  250. #define xlstkcheck(n)    {if (xlstack - (n) < xlstkbase) xlstkoverflow();}
  251. #define xlsave(n)    {*--xlstack = &n; n = NIL;}
  252. #define xlprotect(n)    {*--xlstack = &n;}
  253.  
  254. /* check the stack and protect a single pointer */
  255. #define xlsave1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  256.                          *--xlstack = &n; n = NIL;}
  257. #define xlprot1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  258.                          *--xlstack = &n;}
  259.  
  260. /* macros to pop pointers off the stack */
  261. #define xlpop()        {++xlstack;}
  262. #define xlpopn(n)    {xlstack+=(n);}
  263.  
  264. /* macros to manipulate the lexical environment */
  265. #define xlframe(e)    cons(NIL,e)
  266. #define xlbind(s,v)    xlpbind(s,v,xlenv)
  267. #define xlfbind(s,v)    xlpbind(s,v,xlfenv);
  268. #define xlpbind(s,v,e)    {rplaca(e,cons(cons(s,v),car(e)));}
  269.  
  270. /* macros to manipulate the dynamic environment */
  271. #define xldbind(s,v)    {xldenv = cons(cons(s,getvalue(s)),xldenv);\
  272.              setvalue(s,v);}
  273. #define xlunbind(e)    {for (; xldenv != (e); xldenv = cdr(xldenv))\
  274.                setvalue(car(car(xldenv)),cdr(car(xldenv)));}
  275.  
  276. /* type predicates */                   
  277. #define atom(x)        ((x) == NIL || ntype(x) != CONS)
  278. #define null(x)        ((x) == NIL)
  279. #define listp(x)    ((x) == NIL || ntype(x) == CONS)
  280. #define consp(x)    ((x) && ntype(x) == CONS)
  281. #define subrp(x)    ((x) && ntype(x) == SUBR)
  282. #define fsubrp(x)    ((x) && ntype(x) == FSUBR)
  283. #define stringp(x)    ((x) && ntype(x) == STRING)
  284. #define symbolp(x)    ((x) && ntype(x) == SYMBOL)
  285.  
  286. #if (defined(UNIX) || defined(WINTERP))
  287. #define streamp(x)    ((x) && ((ntype(x) == STREAM) || (ntype(x) == XLTYPE_PIPE)))
  288. #else /* !(defined(UNIX) || defined(WINTERP)) */
  289. #define streamp(x)    ((x) && ntype(x) == STREAM)
  290. #endif /* (defined(UNIX) || defined(WINTERP)) */
  291.  
  292. #ifdef WINTERP
  293. #define objectp(x)    ((x) && ((ntype(x) == OBJECT) || (ntype(x) == XLTYPE_WIDGETOBJ)))
  294. #else
  295. #define objectp(x)    ((x) && ntype(x) == OBJECT)
  296. #endif
  297.  
  298. #define fixp(x)        ((x) && ntype(x) == FIXNUM)
  299. #define floatp(x)    ((x) && ntype(x) == FLONUM)
  300. #define vectorp(x)    ((x) && ntype(x) == VECTOR)
  301. #define closurep(x)    ((x) && ntype(x) == CLOSURE)
  302. #define charp(x)    ((x) && ntype(x) == CHAR)
  303. #define ustreamp(x)    ((x) && ntype(x) == USTREAM)
  304. #define structp(x)    ((x) && ntype(x) == STRUCT)
  305. #define boundp(x)    (getvalue(x) != s_unbound)
  306. #define fboundp(x)    (getfunction(x) != s_unbound)
  307.  
  308. #if (defined(UNIX) || defined(WINTERP))
  309. #define pipe_p(x)     ((x) && (ntype(x) == XLTYPE_PIPE))
  310. #endif /* (defined(UNIX) || defined(WINTERP)) */
  311.  
  312. #ifdef WINTERP
  313. #define xtresource_p(x)  ((x) && (ntype(x) == XLTYPE_XT_RESOURCE))
  314. #define pixel_p(x)       ((x) && (ntype(x) == XLTYPE_Pixel))
  315. #define pixmap_p(x)      ((x) && (ntype(x) == XLTYPE_Pixmap))
  316. #define ximage_p(x)      ((x) && (ntype(x) == XLTYPE_XImage))
  317. #define callbackobj_p(x) ((x) && (ntype(x) == XLTYPE_CALLBACKOBJ))
  318. #define timeoutobj_p(x)  ((x) && (ntype(x) == XLTYPE_TIMEOUTOBJ))
  319. #define widgetobj_p(x)   ((x) && (ntype(x) == XLTYPE_WIDGETOBJ))
  320. #define xmstring_p(x)     ((x) && (ntype(x) == XLTYPE_XmString))
  321. #define xevent_p(x)      ((x) && (ntype(x) == XLTYPE_XEvent))
  322. #define xtaccelerators_p(x) ((x) && (ntype(x) == XLTYPE_XtAccelerators))
  323. #define xttranslations_p(x) ((x) && (ntype(x) == XLTYPE_XtTranslations))
  324. #define evhandlerobj_p(x)   ((x) && (ntype(x) == XLTYPE_EVHANDLEROBJ))
  325. #endif                /* WINTERP */
  326.  
  327. /* shorthand functions */
  328. #define consa(x)    cons(x,NIL)
  329. #define consd(x)    cons(NIL,x)
  330.  
  331. /* argument list parsing macros */
  332. #define xlgetarg()    (testarg(nextarg()))
  333. #define xllastarg()    {if (xlargc != 0) xltoomany();}
  334. #define testarg(e)    (moreargs() ? (e) : xltoofew())
  335. #define typearg(tp)    (tp(*xlargv) ? nextarg() : xlbadtype(*xlargv))
  336. #define nextarg()    (--xlargc, *xlargv++)
  337. #define moreargs()    (xlargc > 0)
  338.  
  339. /* macros to get arguments of a particular type */
  340. #define xlgacons()    (testarg(typearg(consp)))
  341. #define xlgalist()    (testarg(typearg(listp)))
  342. #define xlgasymbol()    (testarg(typearg(symbolp)))
  343. #define xlgastring()    (testarg(typearg(stringp)))
  344. #define xlgaobject()    (testarg(typearg(objectp)))
  345. #define xlgafixnum()    (testarg(typearg(fixp)))
  346. #define xlgaflonum()    (testarg(typearg(floatp)))
  347. #define xlgachar()    (testarg(typearg(charp)))
  348. #define xlgavector()    (testarg(typearg(vectorp)))
  349. #define xlgastream()    (testarg(typearg(streamp)))
  350. #define xlgaustream()    (testarg(typearg(ustreamp)))
  351. #define xlgaclosure()    (testarg(typearg(closurep)))
  352. #define xlgastruct()    (testarg(typearg(structp)))
  353.  
  354. #if (defined(UNIX) || defined(WINTERP))
  355. #define xlga_pipe()    (testarg(typearg(pipe_p)))
  356. #endif /* (defined(UNIX) || defined(WINTERP)) */
  357.  
  358. #ifdef WINTERP
  359. #define xlga_timeoutobj()    (testarg(typearg(timeoutobj_p)))
  360. #define xlga_callbackobj()    (testarg(typearg(callbackobj_p)))
  361. #define xlga_ximage()        (testarg(typearg(ximage_p)))
  362. #define xlga_widgetobj()    (testarg(typearg(widgetobj_p)))
  363. #define xlga_xevent()        (testarg(typearg(xevent_p)))
  364. #define xlga_xttranslations()    (testarg(typearg(xttranslations_p)))
  365. #define xlga_xtaccelerators()    (testarg(typearg(xtaccelerators_p)))
  366. #define xlga_evhandlerobj()    (testarg(typearg(evhandlerobj_p)))
  367. #define xlga_xmstring()        (testarg(typearg(xmstring_p)))
  368. #define xlga_pixel()        (testarg(typearg(pixel_p)))
  369. #endif
  370.  
  371. /* function definition structure */
  372. typedef struct {
  373.     char *fd_name;    /* function name */
  374.     int fd_type;    /* function type */
  375.     LVAL (*fd_subr)();    /* function entry point */
  376. } FUNDEF;
  377.  
  378. /* execution context flags */
  379. #define CF_GO        0x0001
  380. #define CF_RETURN    0x0002
  381. #define CF_THROW    0x0004
  382. #define CF_ERROR    0x0008
  383. #define CF_CLEANUP    0x0010
  384. #define CF_CONTINUE    0x0020
  385. #define CF_TOPLEVEL    0x0040
  386. #define CF_BRKLEVEL    0x0080
  387. #define CF_UNWIND    0x0100
  388.  
  389. /* execution context */
  390. typedef struct context {
  391.     int c_flags;            /* context type flags */
  392.     LVAL c_expr;            /* expression (type dependant) */
  393.     jmp_buf c_jmpbuf;            /* longjmp context */
  394.     struct context *c_xlcontext;    /* old value of xlcontext */
  395.     LVAL **c_xlstack;            /* old value of xlstack */
  396.     LVAL *c_xlargv;            /* old value of xlargv */
  397.     int c_xlargc;            /* old value of xlargc */
  398.     LVAL *c_xlfp;            /* old value of xlfp */
  399.     LVAL *c_xlsp;            /* old value of xlsp */
  400.     LVAL c_xlenv;            /* old value of xlenv */
  401.     LVAL c_xlfenv;            /* old value of xlfenv */
  402.     LVAL c_xldenv;            /* old value of xldenv */
  403. } CONTEXT;
  404.  
  405. /* external variables */
  406. extern LVAL **xlstktop;           /* top of the evaluation stack */
  407. extern LVAL **xlstkbase;    /* base of the evaluation stack */
  408. extern LVAL **xlstack;        /* evaluation stack pointer */
  409. extern LVAL *xlargstkbase;    /* base of the argument stack */
  410. extern LVAL *xlargstktop;    /* top of the argument stack */
  411. extern LVAL *xlfp;        /* argument frame pointer */
  412. extern LVAL *xlsp;        /* argument stack pointer */
  413. extern LVAL *xlargv;        /* current argument vector */
  414. extern int xlargc;        /* current argument count */
  415.  
  416. /* external procedure declarations */
  417. extern LVAL xleval();        /* evaluate an expression */
  418. extern LVAL xlapply();        /* apply a function to arguments */
  419. extern LVAL xlsubr();        /* enter a subr/fsubr */
  420. extern LVAL xlenter();        /* enter a symbol */
  421. extern LVAL xlmakesym();    /* make an uninterned symbol */
  422. extern LVAL xlgetvalue();    /* get value of a symbol (checked) */
  423. extern LVAL xlxgetvalue();    /* get value of a symbol */
  424. extern LVAL xlgetfunction();    /* get functional value of a symbol */
  425. extern LVAL xlxgetfunction();    /* get functional value of a symbol (checked) */
  426. extern LVAL xlexpandmacros();    /* expand macros in a form */
  427. extern LVAL xlgetprop();    /* get the value of a property */
  428. extern LVAL xlclose();        /* create a function closure */
  429.  
  430. /* argument list parsing functions */
  431. extern LVAL xlgetfile();          /* get a file/stream argument */
  432. extern LVAL xlgetfname();    /* get a filename argument */
  433.  
  434. /* error reporting functions (don't *really* return at all) */
  435. extern LVAL xltoofew();        /* report "too few arguments" error */
  436. extern LVAL xlbadtype();    /* report "bad argument type" error */
  437.  
  438.